package com.etc.service.impl;

import com.etc.entity.Counthhf;
import com.etc.entity.User;
import com.etc.mapper.UserMapper;
import com.etc.service.UserService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void saveUser(User user) {

        userMapper.saveUser(user);
    }

    @Override
    public PageInfo<User> queryAllUser() {

        List<User> users = userMapper.queryAllUser();
//        System.out.println("S:"+users);
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

    @Override
    public void deleteUser(int userid) {
        userMapper.deleteUser(userid);
    }

    @Override
    public User updateUser(int userid) {
        User user = userMapper.queryOneUser(userid);
        return user;
    }

    @Override
    public void updateUser2(User user) {
        userMapper.updateUser(user);

    }

    @Override
    public Counthhf queryCount() {
        Counthhf count = userMapper.queryCount();
//        System.out.println("S:"+count);
        return count;
    }

    @Override
    public Counthhf quserCountByNamePhone(@Param("username") String username, @Param("phone") String phone) {
        System.out.println("S:"+username+"-"+phone);
        Counthhf countBy = userMapper.quserCountByNamePhone(username,phone);
        System.out.println(countBy);
        return countBy;
    }

    @Override
    public List<User> queryByNamePhone(User user) {
        System.out.println("S:"+user);
        List<User> queryByNamePhone = userMapper.queryByNamePhone(user.getUsername(), user.getPhone());
        System.out.println("S:"+queryByNamePhone);
        return queryByNamePhone;
    }


}
